﻿using System.Collections.Generic;
using MaxStoreErp.Core.Exceptions;
using MaxStoreShop.Domain.Directories;
using MaxStoreShop.Logic.RepositoriesContracts.Directories;
using MaxStoreShop.Logic.ServicesContracts.Directories;

namespace MaxStoreShop.Logic.Services.Directories
{
    public class StorageLocationService : IStorageLocationService
    {
        readonly IStorageLocationRepository _repository;

        public StorageLocationService(IStorageLocationRepository repository)
        {
            _repository = repository;
        }

        public IEnumerable<StorageLocation> GetAllStorageLocations()
        {
            return _repository.GetAllStorageLocations();
        }

        public void DeleteStorageLocation(StorageLocation storageLocation)
        {
            if (storageLocation == null)
                throw new ErpRuntimeException("Не указано место хранения для удаления!");

            _repository.DeleteStorageLocation(storageLocation.Id);
        }

        public void SaveStorageLocation(StorageLocation storageLocation)
        {
            if (storageLocation == null)
                throw new ErpRuntimeException("Не указано место хранения для сохранения!");

            if (string.IsNullOrWhiteSpace(storageLocation.Name))
                throw new ErpRuntimeException("Не задано имя сохраняемого места хранения!");

            if (string.IsNullOrWhiteSpace(storageLocation.Barcode))
                throw new ErpRuntimeException("Не задан баркод сохраняемого места хранения!");

            _repository.SaveStorageLocation(storageLocation);
        }
    }
}
